package cc.mrbird.febs.music.service.impl;

import cc.mrbird.febs.music.dao.MusicMoodMapper;
import cc.mrbird.febs.music.domain.MusicMoodBean;
import cc.mrbird.febs.music.service.MusicMoodService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

@Slf4j
@Service("musicMoodService")
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
public class MusicMoodServiceImpl extends ServiceImpl<MusicMoodMapper, MusicMoodBean> implements MusicMoodService {
    @Autowired
    MusicMoodMapper musicMoodMapper;

    @Override
    public void updateMusicMood(MusicMoodBean musicMoodBean) throws Exception {
        if (musicMoodMapper.countMusicMood(musicMoodBean) == 0) {
            save(musicMoodBean);
        } else {
            updateById(musicMoodBean);
        }
    }
}
